package com.mooco.dongba.sys.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.mooco.dongba.common.pojo.PageObject;
import com.mooco.dongba.sys.dao.SysLogDao;
import com.mooco.dongba.sys.pojo.SysLog;
import com.mooco.dongba.sys.service.SysLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysLogServiceImpl implements SysLogService {
    @Autowired
    private SysLogDao sysLogDao;

    @Override
    public PageObject<SysLog> findPageObjects(String username, Integer pageCurrent) {
        // 1、参数校验
        if (pageCurrent == null || pageCurrent <= 0)
            throw new IllegalArgumentException("页码值无效");

        // 2、分页获取数据，借助PageHelper
        int pageSize = 3;// 设置每页大小
        Page<SysLog> page = PageHelper.startPage(pageCurrent, pageSize);
        List<SysLog> records = sysLogDao.findPageObjects(username);
        return new PageObject<>((int)page.getTotal(), pageSize, pageCurrent, records);
    }
}
